//
//  pWallView.m
//  HengHuaSupervision
//
//  Created by wanglong8889@126.com on 14-4-1.
//  Copyright (c) 2014年 XD-XY. All rights reserved.
//

#import "pWallView.h"
#import "XDTools.h"
#import "XDHeader.h"
#import "UIImageView+WebCache.h"
@implementation pWallView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.photoView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 225, 161)];
        _photoView.image = [UIImage imageNamed:@"4"];
        
        self.timeLabel = [UILabel initLabel:CGRectMake(12, self.photoView.frame.origin.y+_photoView.frame.size.height, 180, 20) textFont:[UIFont systemFontOfSize:13.0] textColor:UIColorFromRGB(0xffffff) textAlignment:NSTextAlignmentLeft];
        _timeLabel.backgroundColor = [UIColor clearColor];
//        _timeLabel.text = @"2014-03-13 09:12:12";
        
        self.locationLabel = [UILabel initLabel:CGRectMake(12, self.timeLabel.frame.origin.y+_timeLabel.frame.size.height, 32, 20) textFont:[UIFont systemFontOfSize:13.0] textColor:UIColorFromRGB(0xffffff) textAlignment:NSTextAlignmentLeft];
        _locationLabel.backgroundColor = [UIColor clearColor];
//        _locationLabel.text = @"顶部";
        
        self.stateLabel = [UILabel initLabel:CGRectMake(_locationLabel.frame.origin.x+_locationLabel.frame.size.width, _locationLabel.frame.origin.y, 130, 20) textFont:[UIFont systemFontOfSize:13.0] textColor:UIColorFromRGB(0xffffff) textAlignment:NSTextAlignmentLeft];
        _stateLabel.backgroundColor = [UIColor clearColor];
//        _stateLabel.text = @"设备到货中";
        
        self.grayView = [[UIView alloc] initWithFrame:CGRectMake(0, self.photoView.frame.origin.y+self.photoView.frame.size.height, 225, 40)];
        _grayView.backgroundColor = RGBA(168, 168, 168);
        
        
        
        [self addSubview:_photoView];
        [self addSubview:_grayView];
        [self addSubview:_timeLabel];
        [self addSubview:_locationLabel];
        [self addSubview:_stateLabel];
        
        
        
    }
    return self;
}
-(void)initpWallView{

    
    NSString *urlStr = [self.pWall.urlString stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSRange range = [self.pWall.urlString rangeOfString:@"Applications"];
    if (range.location == NSNotFound){
        [self.photoView setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"moren_small"]];
    }else{
        NSData *imageData = [[NSData alloc] initWithContentsOfFile:urlStr];
        self.photoView.image = [[UIImage alloc] initWithData:imageData];
    }
    
    self.timeLabel.text = [[XDTools sharedXDTools] intervalSinceNow:self.pWall.time];
    self.locationLabel.text = self.pWall.location;
    self.stateLabel.text = self.pWall.state;
    
    CGRect rect = [XDTools xyAutoSizeOfWidget:self.locationLabel andSize:CGSizeMake(425/2.0f-35,20) andtextFont:13];
    self.locationLabel.frame =CGRectMake(12, self.timeLabel.frame.origin.y+_timeLabel.frame.size.height,rect.size.width, 20);
    self.stateLabel.frame=CGRectMake(_locationLabel.frame.origin.x+_locationLabel.frame.size.width+10, _locationLabel.frame.origin.y, 130, 20);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
